//
//  CoverImgView.m
//  hunba
//
//  Created by 孙智慧 on 16/1/4.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "CoverImgView.h"

@implementation CoverImgView


- (id) initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        
        
        CGRect r=  [UIScreen mainScreen].bounds;
        
        NSInteger width= r.size.width-(18*2);
        NSInteger height = width;
        
        
        CGFloat w;//84,78,64
        if (IsiPhone5) {
            w=64;
        }
        else if(IsiPhone6)
        {
            w=78;
        }
        else if(IsiPhone6P)
        {
            w=84;
        }
        else
        {
            w=40;
        }
        
        CGFloat h=w;
        CGFloat x=w/2;
        CGFloat y=x;
        
        _albumImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x,y, width-w, height-h)];
        
        _albumImageView.layer.cornerRadius=(height-h)/2;
        _albumImageView.clipsToBounds=true;
        
 
        
        [self addSubview:_albumImageView];
        
    }
    return self;
}

- (void) startRoating
{
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.fromValue= [NSNumber numberWithFloat:0.0];
    animation.toValue=[NSNumber numberWithFloat:M_PI*2];
    animation.repeatCount= MAXFLOAT;
    animation.duration = 20.0;
    animation.removedOnCompletion=NO;
    [self.layer addAnimation:animation forKey:nil];
}
- (void) pasumeRoation
{
    CFTimeInterval pasueTime=  [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
    self.layer.speed = 0.0;
    self.layer.timeOffset= pasueTime;
    
}
- (void) resmeRoation
{
    CFTimeInterval pausedTime = self.layer.timeOffset;
    self.layer.speed=1.0;
    self.layer.timeOffset=0.0;
    self.layer.beginTime=0.0;
    CFTimeInterval timeSpan=[self.layer convertTime:CACurrentMediaTime() fromLayer:nil]- pausedTime;
    self.layer.beginTime=timeSpan;
}
@end
